package com.kayang.dd.service;


import com.kayang.common.HttpResilience4jCommand;
import com.kayang.common.aop.IService;
import com.kayang.common.aop.SPEnable;
import com.kayang.dd.pojo.DDcontext;
import com.kayang.dd.pojo.PersonalTaskModel;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class TaskService implements IService {
    @Override
    public String getBeforeSp() {
        return null;
    }

    @Override
    public String getAfterSp() {
        return null;
    }

    @SPEnable
    public Map creatTask(Map param, DDcontext context, Map headers){

        HttpResilience4jCommand httpResilience4jCommand = new HttpResilience4jCommand(context.getUrl(), context.getMethod(), param, headers);
        Map ret = httpResilience4jCommand.execute();
        context.setRespbody(ret);
        return ret;
    }

    @SPEnable
    public Map updateTask(Map param, DDcontext context, Map headers){
        HttpResilience4jCommand httpResilience4jCommand = new HttpResilience4jCommand(context.getUrl(), context.getMethod(), param, headers);
        Map ret = httpResilience4jCommand.execute();
        context.setRespbody(ret);
        return ret;
    }

    @SPEnable
    public Map deleteTask( DDcontext context, Map headers){
        HttpResilience4jCommand httpResilience4jCommand = new HttpResilience4jCommand(context.getUrl(), context.getMethod(), headers);
        Map ret = httpResilience4jCommand.execute();
        context.setRespbody(ret);
        return ret;
    }

    public Map creatPersonalTask(PersonalTaskModel personalTaskModel, DDcontext context, Map headers) {
        HttpResilience4jCommand httpResilience4jCommand = new HttpResilience4jCommand(context.getUrl(), context.getMethod(), personalTaskModel.toMap(personalTaskModel), headers);
        Map ret = httpResilience4jCommand.execute();
        context.setRespbody(ret);
        return ret;
    }
}
